/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: zhongyisheng
 * Date: 2025-05-20
 * Time: 22:13
 */
//class MyArray{
//    public Object[] array = new Object[10];
//
//    public void setValue(int pos,Object val) {
//        array[pos]=val;
//    }
//    public Object getValue(int pos){
//        return array[pos];
//    }
//
//}

class MyArray<E>{
    public Object[] array = new Object[10];

    public void setValue(int pos,E val) {
        array[pos]=val;
    }
    public E getValue(int pos){
        return (E)array[pos];
    }

}
public class Test2 {
    public static void main(String[] args) {
        MyArray<Integer> myArray = new MyArray<>();
        myArray.setValue(0, 10);
//        myArray.setValue(1,"hello");自动检查
        Integer i = myArray.getValue(0);
        System.out.println(i);

        MyArray<String> myArray2 = new MyArray<>();
        myArray2.setValue(0,"hello");
        String str = myArray2.getValue(0);
        System.out.println(str);

    }
}
